| Conditions | 1 |
| Paths | 1 |
| Total Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* |
||
| 10 | define(['jquery', 'underscore'], function($, _) { |
||
| 11 | |||
| 12 | 'use strict'; |
||
| 13 | |||
| 14 | var denormalizeTag = function(property, tag, tags) { |
||
| 15 | if (!tags[tag.name]) { |
||
| 16 | tags[tag.name] = { |
||
| 17 | properties: {}, |
||
| 18 | highestProperty: property, |
||
| 19 | highestPriority: tag.priority, |
||
| 20 | lowestProperty: property, |
||
| 21 | lowestPriority: tag.priority |
||
| 22 | }; |
||
| 23 | tags[tag.name].properties[tag.priority] = [property]; |
||
| 24 | |||
| 25 | return; |
||
| 26 | } |
||
| 27 | |||
| 28 | if (!tags[tag.name].properties[tag.priority]) { |
||
| 29 | tags[tag.name].properties[tag.priority] = [property]; |
||
| 30 | } else { |
||
| 31 | tags[tag.name].properties[tag.priority].push(property); |
||
| 32 | } |
||
| 33 | |||
| 34 | // replace highest if priority is higher |
||
| 35 | if (tags[tag.name].highestPriority < tag.priority) { |
||
| 36 | tags[tag.name].highestProperty = property; |
||
| 37 | tags[tag.name].highestPriority = tag.priority; |
||
| 38 | } |
||
| 39 | |||
| 40 | // replace lowest if priority is lower |
||
| 41 | if (tags[tag.name].lowestPriority > tag.priority) { |
||
| 42 | tags[tag.name].lowestProperty = property; |
||
| 43 | tags[tag.name].lowestPriority = tag.priority; |
||
| 44 | } |
||
| 45 | }; |
||
| 46 | |||
| 47 | return { |
||
| 48 | generate: function($form) { |
||
| 49 | var $items = $form.find('*[data-property]'); |
||
| 50 | |||
| 51 | if ($items.length === 0) { |
||
| 52 | return {}; |
||
| 53 | } |
||
| 54 | |||
| 55 | var propertyConfiguration = { |
||
| 56 | tags: {} |
||
| 57 | }; |
||
| 58 | |||
| 59 | $items.each(function() { |
||
| 60 | var $this = $(this), |
||
| 61 | property = $this.data('property'); |
||
| 62 | |||
| 63 | property.$el = $this; |
||
| 64 | |||
| 65 | // remove property from dom |
||
| 66 | $this.data('property', null); |
||
| 67 | $this.removeAttr('data-property'); |
||
| 68 | |||
| 69 | propertyConfiguration[property.name] = property; |
||
| 70 | |||
| 71 | _.each(property.tags, function(tag) { |
||
| 72 | denormalizeTag(property, tag, propertyConfiguration.tags); |
||
| 73 | }); |
||
| 74 | |||
| 75 | return propertyConfiguration; |
||
| 76 | }); |
||
| 77 | |||
| 78 | return propertyConfiguration; |
||
| 79 | } |
||
| 80 | }; |
||
| 81 | }); |
||
| 82 |